home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / modem / wsftp2.zip / WS_PAINT.C < prev    next >
C/C++ Source or Header  |  1994-06-03  |  6KB  |  177 lines

  1. /***************************************************************************
  2.   Windows Sockets Client Application Support Module
  3.  
  4.   Written by:
  5.       John A. Junod             Internet: <junodj@gordon-emh2.army.mil>
  6.       267 Hillwood Street                 <zj8549@trotter.usma.edu>
  7.       Martinez, GA 30907      Compuserve: 72321,366 
  8.  
  9.   This program executable and all source code is released into the public
  10.   domain.  It would be nice (but is not required) to give me a little 
  11.   credit for any use of this code.
  12.  
  13.   THE INFORMATION AND CODE PROVIDED IS PROVIDED AS IS WITHOUT WARRANTY 
  14.   OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  15.   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  16.   PURPOSE. IN NO EVENT SHALL JOHN A. JUNOD BE LIABLE FOR ANY DAMAGES 
  17.   WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS 
  18.   OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF JOHN A. JUNOD HAS BEEN 
  19.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  20.  
  21. *****************************************************************************/
  22. /*
  23.   MODULE: WS_PAINT.C  (main window (debug) display routines)
  24. */
  25.  
  26. #include "ws_glob.h"
  27. #include "ws_ftp.h"
  28. #include "version.h"
  29.  
  30. #include <stdarg.h>
  31.  
  32. extern struct win_info DBUGWINDOW;
  33.  
  34. void ReleaseDisplayMem()       { ReleaseWindowMem(&DBUGWINDOW); }
  35.  
  36. void DoAddLine(LPSTR szString) { DoAddWindowLine(&DBUGWINDOW,szString); }
  37.  
  38. void DoPrintf(char *szFormat,...)
  39. {
  40.    va_list vaArgs;
  41.    static char szBuf[256];
  42.  
  43.    va_start(vaArgs,szFormat);
  44.    if(vsprintf(szBuf,szFormat,vaArgs)!=EOF)
  45.      DoAddWindowLine(&DBUGWINDOW,szBuf);
  46.    va_end(vaArgs);
  47. }
  48.  
  49. int GetLocalInfo()
  50. {
  51.   int nRc;
  52.   struct hostent *hostptr;
  53.  // char *ptr;
  54.   struct in_addr *iptr;
  55.  
  56. //DoWindowPrintf(&DBUGWINDOW,"System Status: %s", (LPSTR)WSAData.szSystemStatus);
  57.   if((nRc=gethostname((LPSTR)szString,
  58.              MAXHOSTNAMELEN))==SOCKET_ERROR)
  59.     ReturnWSError(WSAGetLastError(),&szMsgBuf2[strlen(szMsgBuf2)]);
  60.   else
  61.     DoWindowPrintf(&DBUGWINDOW,"Local Hostname: %s",szString);
  62.  
  63.   if(!nRc)
  64.   {
  65.     if((hostptr=gethostbyname(szString))==NULL) {
  66.       ReportWindowWSError(&DBUGWINDOW,"gethostbyname",WSAGetLastError());
  67.     } else {
  68.       while ( (iptr = (struct in_addr *) *(hostptr->h_addr_list)) != NULL) {
  69.         DoWindowPrintf(&DBUGWINDOW,"Local Address: %s",inet_ntoa(*iptr));
  70.         hostptr->h_addr_list++;
  71.       }
  72.     }
  73.   }
  74.   DoWindowPrintf(&DBUGWINDOW,"WINSOCK.DLL: %s",(LPSTR)WSAData.szDescription);
  75.   DoWindowPrintf(&DBUGWINDOW,"WS_FTP version %s written by John A. Junod/L. Kahn",VERSION);
  76.   return(TRUE);
  77. }
  78.  
  79. void ReleaseWindowMem(struct win_info *Window)
  80. {
  81.   int nIndex;
  82.   for(nIndex=0;nIndex<Window->nMemPtr;nIndex++)
  83.     GlobalFree(Window->hGMem[nIndex]);
  84.   Window->nMemPtr=0;
  85. }
  86.  
  87. void DoAddWindowLine(struct win_info *Window,LPSTR szString)
  88. {
  89.   GLOBALHANDLE hGlobalMemory;
  90.   LPSTR lpGlobalMemory;
  91.   int nIndex;
  92.   RECT rect;
  93.  
  94.   if(!(bVerbose) && szString[0]=='[')
  95.     return;
  96.  
  97.   if(szString[0]!='[')
  98.     SetStatus((LPSTR)szString);
  99. // SendMessage(hTxtStatus,WM_SETTEXT,0,(LONG)szString);
  100.   // added in some error checking to try to eliminate GPFs
  101.   if(szString) {
  102.     nIndex=strlen(szString);
  103.     if(nIndex>0 && (hGlobalMemory=GlobalAlloc(GMEM_MOVEABLE,nIndex))!=NULL) {
  104.       if((lpGlobalMemory=GlobalLock(hGlobalMemory))!=NULL) {
  105.         lstrcpy(lpGlobalMemory,szString);
  106.         GlobalUnlock(hGlobalMemory);
  107.         if(Window->nMemPtr<90) {
  108.           Window->hGMem[Window->nMemPtr++]=hGlobalMemory;
  109.         } else {
  110.           if(GlobalFree(Window->hGMem[0])==NULL) {
  111.             for(nIndex=0;nIndex<90;nIndex++)
  112.               Window->hGMem[nIndex]=Window->hGMem[nIndex+1];
  113.             Window->hGMem[Window->nMemPtr-1]=hGlobalMemory;
  114.           }
  115.         }
  116.       }
  117.     }
  118.   }
  119.   GetClientRect(Window->hWnd,&rect);
  120.   rect.top=min(0,(Window->nMemPtr-Window->nVpos-1))*Window->nLineHeight;
  121.  
  122.   if(Window->nMemPtr > (Window->nVpos+Window->nScreenRows))
  123.     PostMessage(Window->hWnd,WM_VSCROLL,SB_LINEDOWN,0L);
  124.   else
  125.     InvalidateRect(Window->hWnd,&rect,TRUE);
  126.  
  127.   UpdateWindow(Window->hWnd);
  128. }
  129.  
  130. void DoWindowPrintf(struct win_info *Window,char *szFormat,...)
  131. {
  132.    va_list vaArgs;
  133.    static char szBuf[256];
  134.  
  135.    va_start(vaArgs,szFormat);
  136.    if(vsprintf(szBuf,szFormat,vaArgs)!=EOF)
  137.      DoAddWindowLine(Window,szBuf);
  138.    va_end(vaArgs);
  139. }
  140.  
  141. void DoWindowPaint(struct win_info *Window)
  142. {
  143.   HDC         hDC;   // handle for the display device
  144.   PAINTSTRUCT ps;    // holds PAINT information
  145. //  int         nRc;
  146.   int         nIndex;
  147.   LPSTR       lpMem;
  148.  
  149.   RECT rRect;
  150.   TEXTMETRIC tm;
  151.  
  152.   memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  153.   hDC = BeginPaint(Window->hWnd, &ps);
  154.   // Included as the background is not a pure color
  155.   SetBkMode(hDC, TRANSPARENT);
  156.   GetTextMetrics(hDC,&tm);
  157.   Window->nLineHeight=tm.tmHeight+tm.tmExternalLeading;
  158.   GetClientRect(Window->hWnd,&rRect);
  159.   Window->nScreenRows=rRect.bottom/Window->nLineHeight;
  160.  
  161.   if(Window->nScreenRows >= Window->nMemPtr)
  162.       ShowScrollBar(Window->hWnd,SB_VERT,FALSE);
  163.   else
  164.       ShowScrollBar(Window->hWnd,SB_VERT,TRUE);
  165.  
  166.   for(nIndex=0;(nIndex+Window->nVpos)<Window->nMemPtr;nIndex++) {
  167.     lpMem=GlobalLock(Window->hGMem[nIndex+Window->nVpos]);
  168.     if(lpMem!=NULL) {
  169.       TextOut(hDC,20,nIndex*Window->nLineHeight,lpMem,lstrlen(lpMem));
  170.       GlobalUnlock(Window->hGMem[nIndex+Window->nVpos]);
  171.     }
  172.   }
  173.   // Inform Windows painting is complete
  174.   EndPaint(Window->hWnd, &ps);
  175. }
  176.  
  177.